const Router = require('koa-router')

const router = new Router({ prefix: '/goods' })

const { auth, hadAdminPremission } = require('../middleware/auth.middleware')
const { uploadType } = require('../middleware/upload.middleware')
const { validator } = require('../middleware/goods.middleware')
const { upload, create, update, remove, restore, findAll } = require('../controller/goods.controller')


// 图片上传接口
router.post('/upload', auth, hadAdminPremission, uploadType, upload)

// 商品添加
router.post('/', auth, hadAdminPremission, validator, create)

// 商品修改
router.put('/:id', auth, hadAdminPremission, validator, update)

// 商品上下架
router.post('/:id/off', auth, hadAdminPremission, remove)
router.post('/:id/on', auth, hadAdminPremission, restore)

// 获取商品列表
router.get('/', findAll)

module.exports = router
